<template>
  <div class="app-container">
    <el-form :model="searchForm" :inline="true">
      <el-col :span="20">
        <el-form :model="searchForm" inline @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model="searchForm.fuzzy"
              style="width: 250px"
              placeholder="仪器名称/仪器编号/仪器型号"
              clearable
              @keyup.enter.native="handleSearch"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              class="iconfont icon-chaxun1"
              @click="handleSearch"
            >
              查询</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="4" class="search-right">
        <el-button type="text" @click="BatchRecordDownload"
          >批量记录下载</el-button
        >
      </el-col>
    </el-form>
    <div>
      <el-table
        ref="stockTable"
        stripe
        border
        :data="tableData"
        class="table-item"
        highlight-current-row
        :header-cell-style="{ background: '#ECF3FC' }"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <template slot="empty">
          <div class="table_empty">
            <div class="empty_tips">
              <span> 暂无数据 </span>
            </div>
          </div>
        </template>

        <el-table-column
          type="selection"
          fixed="left"
          width="55"
          align="center"
        />

        <el-table-column
          type="index"
          fixed="left"
          width="55"
          align="center"
          label="序号"
        />
        <el-table-column
          prop="number"
          label="仪器编号"
          fixed="left"
          width="80"
          align="center"
        />
        <el-table-column
          prop="name"
          label="仪器名称"
          fixed="left"
          width="80"
          align="center"
        />
        <el-table-column
          prop="model"
          label="仪器型号"
          width="80"
          align="center"
        />
        <el-table-column
          prop="manufacturer"
          label="仪器品牌"
          min-width="80"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="serialNumber"
          label="出厂编号"
          min-width="100px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="deviceType"
          label="仪器类别"
          width="110px"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.deviceType == '1'">现场采样仪器</span>
            <span v-if="scope.row.deviceType == '2'">现场检测仪器</span>
            <span v-if="scope.row.deviceType == '3'">实验室仪器</span>
            <span v-if="scope.row.deviceType == '4'">校准仪器</span>
            <span v-if="scope.row.deviceType == '5'">样品制备仪器</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="classType"
          label="检测类别"
          min-width="100px"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.classType == '1'"> 水</span>
            <span v-if="scope.row.classType == '2'">气</span>
            <span v-if="scope.row.classType == '3'">噪声</span>
            <span v-if="scope.row.classType == '4'"
              >土壤、底泥、固废、污泥和生活垃圾</span
            >
            <span v-if="scope.row.classType == '5'">样品制备</span>
            <span v-if="scope.row.classType == '6'">小型分析仪器</span>
            <span v-if="scope.row.classType == '7'">色谱仪 </span>
            <span v-if="scope.row.classType == '8'">光谱仪</span>
            <span v-if="scope.row.classType == '9'">质谱仪</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="position"
          label="放置地点"
          min-width="80px"
          align="center"
        />
        <el-table-column
          prop="department"
          label="所属部门"
          min-width="80px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="maintainUser"
          label="维修/保养人"
          min-width="120px"
          align="center"
        />
        <el-table-column
          prop="maintainDate"
          label="最近维修/保养日期"
          min-width="120px"
          align="center"
        />
        <el-table-column
          prop="maintainContent"
          label="维修/保养内容"
          min-width="120px"
          align="center"
        />

        <el-table-column fixed="right" align="center" label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="text" @click="lookInfo(scope.row)">
              维修登记</el-button
            >
            <div class="erc-divider-vertical" />
            <el-button type="text" @click="RecordsBox(scope.row)">
              维修记录</el-button
            >
            <el-button
              Permi="['system:role:edit']"
              type="text"
              @click="editInfo(scope.row)"
            >
              保养登记</el-button
            >

            <div class="erc-divider-vertical" />
            <el-button type="text" @click="submitExamine(scope.row)">
              保养记录</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="float: right">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="searchForm.pageNumber"
        :limit.sync="searchForm.pageSize"
        @pagination="handleSearch"
      />
    </div>
    <!-- 弹框批量记录下载 -->
    <el-dialog
      title="批量记录下载"
      :visible.sync="purchaseVisible"
      center
      @closed="dialogClose"
      top="5vh"
      width="500px"
    >
      <el-form :model="searchForm" label-width="110px">
        <el-row :gutter="20">
          <el-col :span="20">
            <!-- <el-form-item prop="startTime" label="选择日期范围:">
              <el-date-picker
                style="width: 110%"
                value-format="yyyy-MM-dd"
                type="date"
                v-model="startTime"
              >
              </el-date-picker>
            </el-form-item> -->
            <el-form-item prop="start,end" label="选择日期范围:">
              <div class="block">
                <el-date-picker
                  style="width: 110%"
                  v-model="startEnd"
                  type="daterange"
                  range-separator="~"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </div>
            </el-form-item>
            <el-form-item label="选择维修/保养" prop="type">
              <el-select v-model="type" @change="typeValue" style="width: 110%">
                <el-option label="全部记录" value="3"></el-option>
                <el-option label="维修记录" value="2"></el-option>
                <el-option label="保养记录" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="purchaseVisible = false">取消</el-button>
        <el-button type="primary" @click="downloadTem">确认</el-button>
      </div>
    </el-dialog>
    <!-- 维修登记弹框 -->
    <el-dialog
      title="仪器维修登记"
      :visible.sync="MaintenanceVisible"
      center
      @closed="dialogClose"
      top="5vh"
      width="700px"
    >
      <el-form :model="Maintenance" label-width="110px">
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item prop="maintainDate" label="维修日期:">
              <el-date-picker
                style="width: 40%"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="date"
                v-model="Maintenance.maintainDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="故障描述:" prop="errorContent">
              <el-input
                v-model="Maintenance.errorContent"
                type="textarea"
                :rows="4"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="维修内容:" prop="maintainContent">
              <el-input
                v-model="Maintenance.maintainContent"
                type="textarea"
                :rows="4"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="验收内容:" prop="checkContent">
              <el-input
                v-model="Maintenance.checkContent"
                type="textarea"
                :rows="4"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="维修单位名称:" prop="maintainName">
              <el-input
                v-model="Maintenance.maintainName"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="联系人:" prop="maintainUser">
              <el-input
                v-model="Maintenance.maintainUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="联系电话:" prop="maintainPhone">
              <el-input
                v-model="Maintenance.maintainPhone"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="maintainDate" label="维修日期:">
              <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="date"
                v-model="Maintenance.maintainDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="送修人:" prop="sendUser">
              <el-input v-model="Maintenance.sendUser" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="sendDate" label="送修日期:">
              <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="date"
                v-model="Maintenance.sendDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="取回人:" prop="backUser">
              <el-input v-model="Maintenance.backUser" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="backDate" label="取回日期:">
              <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="date"
                v-model="Maintenance.backDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="验收人:" prop="checkUser">
              <el-input v-model="Maintenance.checkUser" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="checkDate" label="验收日期:">
              <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="date"
                v-model="Maintenance.checkDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="MaintenanceVisible = false">取消</el-button>
        <el-button type="primary" @click="MaintenanceConfirm()">确认</el-button>
      </div>
    </el-dialog>
    <!-- 仪器维修记录弹框 -->
    <el-dialog
      title="仪器维修记录"
      :visible.sync="MaintenanceRecords"
      width="1200px"
      center
      :close-on-click-modal="false"
    >
      <div class="install-title">仪器基础信息</div>
      <el-form label-width="80px">
        <el-row :gutter="14">
          <el-col :span="6">
            <el-form-item label="仪器编号:">
              {{ chooseSearchForm.number }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="仪器名称:">
              {{ chooseSearchForm.name }}</el-form-item
            >
          </el-col>
          <el-col :span="6">
            <el-form-item label="型号规格:">
              {{ chooseSearchForm.model }}</el-form-item
            >
          </el-col>
          <el-col :span="6">
            <el-form-item label="生产厂家:">
              {{ chooseSearchForm.manufacturer }}</el-form-item
            >
          </el-col>
        </el-row>
        <el-row :gutter="12">
          <el-col :span="6">
            <el-form-item label="仪器类别:">
              <span v-if="chooseSearchForm.deviceType == '1'"
                >现场采样仪器</span
              >
              <span v-if="chooseSearchForm.deviceType == '2'"
                >现场检测仪器</span
              >
              <span v-if="chooseSearchForm.deviceType == '3'">实验室仪器</span>
              <span v-if="chooseSearchForm.deviceType == '4'">校准仪器</span>
              <span v-if="chooseSearchForm.deviceType == '5'"
                >样品制备仪器</span
              >
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="检测类别:">
              <span v-if="chooseSearchForm.classType == '1'"> 水</span>
              <span v-if="chooseSearchForm.classType == '2'">气</span>
              <span v-if="chooseSearchForm.classType == '3'">噪声</span>
              <span v-if="chooseSearchForm.classType == '4'"
                >土壤、底泥、固废、污泥和生活垃圾</span
              >
              <span v-if="chooseSearchForm.classType == '5'">样品制备</span>
              <span v-if="chooseSearchForm.classType == '6'">小型分析仪器</span>
              <span v-if="chooseSearchForm.classType == '7'">色谱仪 </span>
              <span v-if="chooseSearchForm.classType == '8'">光谱仪</span>
              <span v-if="chooseSearchForm.classType == '9'">质谱仪</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div
        style=" 
          display: flex;
          align-items: center;
          line-height: 50px;
          padding-left: 20px;
          color: #fff;
          background-color: #d7dae2;
          flex-wrap: wrap;
          justify-content: space-between
          margin-bottom: 10px;"
      >
        <div>仪器维修记录</div>
        <div class="block" style="margin: 0 40px 0 0">
          <span class="demonstration">日期选择：</span>
          <el-date-picker
            type="daterange"
            v-model="startEnd"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="changeStartEnd"
          >
          </el-date-picker>
        </div>
      </div>
      <el-table
        :model="searchForm"
        border
        stripe
        :data="MaintenanceData"
        highlight-current-row
        :header-cell-style="{ background: '#ECF3FC' }"
        style="width: 100%"
        ref="MaintenanceData"
      >
        <el-table-column
          type="index"
          width="50"
          label="序号"
          fixed="left"
          align="center"
        />
        <el-table-column
          prop="maintainDate"
          label="维修日期"
          width="100"
          fixed="left"
          align="center"
        />
        <el-table-column
          prop="errorContent"
          label="故障描述"
          width="220px"
          align="center"
        />

        <el-table-column
          prop="maintainContent"
          label="维修内容"
          width="220px"
          align="center"
        >
        </el-table-column>

        <el-table-column
          prop="checkContent"
          label="验收内容"
          width="220px"
          align="center"
        />
        <el-table-column
          prop="sendUser"
          label="维修人"
          width="110"
          align="center"
        />
        <el-table-column
          prop="checkUser"
          label="验收人"
          width="110px"
          align="center"
        />
        <el-table-column fixed="right" align="center" label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" @click="handleUpdate1(scope.row)">
              修改</el-button
            >
            <el-button type="text" @click="handleDelete(scope.row)">
              删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="MaintenanceRecords = false">取消</el-button>
        <el-button type="primary" @click="handleDownloads"
          >维修记录下载</el-button
        >
      </div>
    </el-dialog>
    <!-- 维修记录修改 -->
    <el-dialog
      title="维修记录修改"
      :visible.sync="MaintenanceRevise"
      center
      @closed="dialogClose"
      top="5vh"
      width="700px"
    >
      <el-form
        :model="MaintenanceData1"
        ref="MaintenanceData1"
        label-width="110px"
      >
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item prop="maintainDate" label="维修日期:">
              <el-date-picker
                style="width: 40%"
                value-format="yyyy-MM-dd"
                type="date"
                v-model="MaintenanceData1.maintainDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="故障描述:" prop="errorContent">
              <el-input
                v-model="MaintenanceData1.errorContent"
                type="textarea"
                :rows="4"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="维修内容:" prop="maintainContent">
              <el-input
                v-model="MaintenanceData1.maintainContent"
                type="textarea"
                :rows="4"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="验收内容:" prop="checkContent">
              <el-input
                v-model="MaintenanceData1.checkContent"
                type="textarea"
                :rows="4"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="维修单位名称:" prop="maintainName">
              <el-input
                v-model="MaintenanceData1.maintainName"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="联系人:" prop="maintainUser">
              <el-input
                v-model="MaintenanceData1.maintainUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="联系电话:" prop="maintainPhone">
              <el-input
                v-model="MaintenanceData1.maintainPhone"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="maintainDate" label="维修日期:">
              <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd"
                type="date"
                v-model="MaintenanceData1.maintainDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="送修人:" prop="sendUser">
              <el-input
                v-model="MaintenanceData1.sendUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="sendDate" label="送修日期:">
              <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd"
                type="date"
                v-model="MaintenanceData1.sendDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="取回人:" prop="backUser">
              <el-input
                v-model="MaintenanceData1.backUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="backDate" label="取回日期:">
              <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd"
                type="date"
                v-model="MaintenanceData1.backDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="验收人:" prop="checkUser">
              <el-input
                v-model="MaintenanceData1.checkUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="checkDate" label="验收日期:">
              <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd"
                type="date"
                v-model="MaintenanceData1.checkDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="MaintenanceRevise = false">取消</el-button>
        <el-button type="primary" @click="confirmDialog">确认</el-button>
      </div>
    </el-dialog>
    <!-- 保养登记弹框 -->
    <el-dialog
      title="仪器保养登记"
      :visible.sync="maintenance1Visible"
      center
      @closed="dialogClose"
      top="5vh"
      width="700px"
    >
      <el-form :model="Maintenanceadd" label-width="110px">
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item prop="maintainDate" label="保养日期:">
              <el-date-picker
                style="width: 40%"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="date"
                v-model="Maintenanceadd.maintainDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="保养内容:" prop="maintainContent">
              <el-input
                v-model="Maintenanceadd.maintainContent"
                type="textarea"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="保养备注:" prop="checkContent">
              <el-input
                v-model="Maintenanceadd.checkContent"
                type="textarea"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="保养人:" prop="maintainUser">
              <el-input
                v-model="Maintenanceadd.maintainUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="验收人:" prop="checkUser">
              <el-input
                v-model="Maintenanceadd.checkUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="maintenance1Visible = false">取消</el-button>
        <el-button type="primary" @click="MaintenanceConfirm1">确认</el-button>
      </div>
    </el-dialog>
    <!-- 仪器保养记录弹框 -->
    <el-dialog
      title="仪器保养记录"
      :visible.sync="Maintenancerecord"
      width="1200px"
      center
      :close-on-click-modal="false"
    >
      <div class="install-title">仪器基础信息</div>
      <el-form label-width="80px">
        <el-row :gutter="14">
          <el-col :span="6">
            <el-form-item label="仪器编号:">
              {{ chooseSearchForm.number }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="仪器名称:">
              {{ chooseSearchForm.name }}</el-form-item
            >
          </el-col>
          <el-col :span="6">
            <el-form-item label="型号规格:">
              {{ chooseSearchForm.model }}</el-form-item
            >
          </el-col>
          <el-col :span="6">
            <el-form-item label="生产厂家:">
              {{ chooseSearchForm.manufacturer }}</el-form-item
            >
          </el-col>
        </el-row>
        <el-row :gutter="12">
          <el-col :span="6">
            <el-form-item label="仪器类别:">
              <span v-if="chooseSearchForm.deviceType == '1'"
                >现场采样仪器</span
              >
              <span v-if="chooseSearchForm.deviceType == '2'"
                >现场检测仪器</span
              >
              <span v-if="chooseSearchForm.deviceType == '3'">实验室仪器</span>
              <span v-if="chooseSearchForm.deviceType == '4'">校准仪器</span>
              <span v-if="chooseSearchForm.deviceType == '5'"
                >样品制备仪器</span
              >
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="检测类别:">
              <span v-if="chooseSearchForm.classType == '1'"> 水</span>
              <span v-if="chooseSearchForm.classType == '2'">气</span>
              <span v-if="chooseSearchForm.classType == '3'">噪声</span>
              <span v-if="chooseSearchForm.classType == '4'"
                >土壤、底泥、固废、污泥和生活垃圾</span
              >
              <span v-if="chooseSearchForm.classType == '5'">样品制备</span>
              <span v-if="chooseSearchForm.classType == '6'">小型分析仪器</span>
              <span v-if="chooseSearchForm.classType == '7'">色谱仪 </span>
              <span v-if="chooseSearchForm.classType == '8'">光谱仪</span>
              <span v-if="chooseSearchForm.classType == '9'">质谱仪</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div
        style=" 
          display: flex;
          align-items: center;
          line-height: 50px;
          padding-left: 20px;
          color: #fff;
          background-color: #d7dae2;
          flex-wrap: wrap;
          justify-content: space-between
          margin-bottom: 10px;"
      >
        <div>仪器保养记录</div>
        <div class="block" style="margin: 0 40px 0 0">
          <span class="demonstration">日期选择：</span>
          <el-date-picker
            type="daterange"
            v-model="startEnd"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="changeStart"
          >
          </el-date-picker>
        </div>
      </div>
      <el-table
        :model="searchForm"
        border
        stripe
        :data="MaintenanceData"
        highlight-current-row
        :header-cell-style="{ background: '#ECF3FC' }"
        style="width: 100%"
        ref="MaintenanceData"
      >
        <el-table-column
          type="index"
          width="50"
          label="序号"
          fixed="left"
          align="center"
        />
        <el-table-column
          prop="maintainDate"
          label="保养日期"
          fixed="left"
          align="center"
        />
        <el-table-column
          prop="maintainContent"
          label="保养内容"
          align="center"
        />

        <el-table-column prop="checkContent" label="保养备注" align="center">
        </el-table-column>

        <el-table-column prop="maintainUser" label="保养人" align="center" />
        <el-table-column prop="checkUser" label="验收人" align="center" />
        <el-table-column fixed="right" align="center" label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" @click="handleUpdate2(scope.row)">
              修改</el-button
            >
            <el-button type="text" @click="handleDelete1(scope.row)">
              删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="Maintenancerecord = false">取消</el-button>
        <el-button type="primary" @click="handleDownload"
          >使用记录下载</el-button
        >
      </div>
    </el-dialog>
    <!-- 保养记录修改 -->
    <el-dialog
      title="保养记录修改"
      :visible.sync="maintenance3Visible"
      center
      @closed="dialogClose"
      top="5vh"
      width="700px"
    >
      <el-form
        :model="MaintenanceData2"
        ref="MaintenanceData2"
        label-width="110px"
      >
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item prop="maintainDate" label="保养日期:">
              <el-date-picker
                style="width: 40%"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="date"
                v-model="MaintenanceData2.maintainDate"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="保养内容:" prop="maintainContent">
              <el-input
                v-model="MaintenanceData2.maintainContent"
                type="textarea"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="保养备注:" prop="checkContent">
              <el-input
                v-model="MaintenanceData2.checkContent"
                type="textarea"
                style="width: 113%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="保养人:" prop="maintainUser">
              <el-input
                v-model="MaintenanceData2.maintainUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="验收人:" prop="checkUser">
              <el-input
                v-model="MaintenanceData2.checkUser"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="maintenance3Visible = false">取消</el-button>
        <el-button type="primary" @click="confirmDialog1">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as addMaintenance from "@/api/Maintenance";
import Pagination from "@/components/Pagination"; // Secondary package based on el-pagination
export default {
  components: { Pagination },
  data() {
    return {
      rules: {},
      edit: false,
      submitButt: false,
      modelList: [],
      MaintenanceData: [],
      isEdit: false,
      purchaseForm: {
        name: "",
        model: "",
        amount: "",
        price: ""
      },
      purchaseVisible: false,
      MaintenanceVisible: false,
      MaintenanceRecords: false,
      MaintenanceRevise: false,
      maintenance1Visible: false,
      maintenance3Visible: false,
      Maintenancerecord: false,
      chooseSearchForm: {},
      total: 0,
      getId: "",
      tableData: [],
      type: [
        {
          name: "保养",
          id: "1"
        },
        {
          name: "维修",
          id: "2"
        }
      ],
      total: 0,
      Maintenance: {
        backDate: "",
        backUser: "",
        checkContent: "",
        checkDate: "",
        checkUser: "",
        errorContent: "",
        maintainContent: "",
        maintainDate: "",
        maintainName: "",
        maintainPhone: "",
        maintainUser: "",
        sendDate: "",
        sendUser: "",
        deviceId: "",
        type: ""
      },
      Maintenanceadd: {
        deviceId: "",
        type: ""
      },
      MaintenanceData1: {},
      MaintenanceData2: {},
      searchForm: {
        pageNumber: 1,
        pageSize: 10
      },
      MaintenanceSearchForm: {
        id: "",
        type: ""
      },
      multipleselection: "",
      type: "",
      startEnd: [],
      start: "",
      end: ""
    };
  },

  created() {
    this.handleSearch();
  },

  methods: {
    newPurchase() {
      this.isEdit = false;
      this.edit = true;
      this.purchaseVisible = true;
    },
    handleSearch() {
      addMaintenance.getdeviceApplyList(this.searchForm).then(res => {
        if (res.code === 200 && res.result) {
          console.log(111, res);
          this.tableData = res.result.records;
          console.log(this.tableData);
          this.total = res.result.total;
        }
      });
    },
    handleSelectionChange(val) {
      console.log(val);
      this.multipleselection = val;
      var arr = [];
      for (var item of val) {
        console.log(item.id);
        arr.push(item.id);
        console.log(arr + []);
        this.Selection = arr + [];
      }
    },
    dialogClose() {
      this.purchaseForm = {};
      this.edit = false;
      this.submitButt = false;
    },
    handleCreate() {
      this.approveVisible = "create";
    },
    BatchRecordDownload() {
      if (this.multipleselection.length != 0) {
        this.purchaseVisible = true;
      } else {
        this.$message({
          message: "最少选择一条记录",
          type: "warning"
        });
      }
    },
    typeValue(e) {
      this.type = e;
      console.log(this.type);
    },
    downloadTem() {
      this.start = this.startEnd[0];
      this.end = this.startEnd[1];
      var url =
        "/api/excel/exportDeviceMaintain?id=" +
          this.Selection +
          "&type=" +
          this.type +
          "&start=" +
          this.start ||
        "" + "&end=" + this.end ||
        "";
      window.open(url);
      this.purchaseVisible = false;
    },
    //---------------------维修登记--------------------------
    //开弹窗
    lookInfo(row) {
      console.log(row);
      this.Maintenance.deviceId = row.id;
      this.Maintenance.type = "2";
      console.log(this.Maintenance.deviceId);
      this.MaintenanceVisible = true;
    },
    // 传数据
    MaintenanceConfirm() {
      addMaintenance.add(this.Maintenance).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: "成功",
            message: res.message,
            type: "success"
          });
          this.handleSearch();
          this.MaintenanceVisible = false;
        } else {
          this.$notify({
            title: "失败",
            message: res.message,
            type: "error"
          });
          this.MaintenanceVisible = false;
        }
      });
    },
    //---------------------维修记录--------------------------
    RecordsBox(row) {
      this.startEnd = "";
      this.MaintenanceSearchForm.start = "";
      this.MaintenanceSearchForm.end = "";
      this.MaintenanceRecords = true;
      this.chooseSearchForm = row;
      console.log(this.chooseSearchForm);
      this.MaintenanceSearchForm.id = row.id;
      this.MaintenanceSearchForm.type = "2";

      addMaintenance.maintainList(this.MaintenanceSearchForm).then(res => {
        if (res.code === 200 && res.result) {
          console.log(111, res);
          this.MaintenanceData = res.result.records;
          console.log(this.MaintenanceData);
          this.total = res.result.total;
        }
      });
    },
    // 修改
    handleUpdate1(row) {
      // console.log(1111);
      this.MaintenanceRevise = true;
      console.log(row);
      this.MaintenanceData1 = row;
    },
    // 修改确认
    confirmDialog() {
      this.$refs.MaintenanceData1.validate(valid => {
        if (valid) {
          addMaintenance
            .update(this.MaintenanceData1)
            .then(request => {
              this.$notify({
                title: "成功",
                message: request.message,
                type: "success"
              });
              this.MaintenanceRevise = false;
              this.$refs.customForm.resetFields();
            })
            .catch(() => {});
        } else {
          return false;
        }
      });
    },
    // 删除
    handleDelete(row) {
      console.log(row);
      this.id = row.id;
      console.log(this.id);
      this.$confirm(
        '是否确认删除名称为"' + row.createUser + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          addMaintenance
            .deletedelete({
              id: this.id
            })
            .then(result => {
              if (result.code === 200) {
                this.$notify({
                  title: "成功",
                  message: result.message,
                  type: "success"
                });
                this.MaintenanceRecords = false;
                console.log(111);
              } else {
                this.$notify({
                  title: "失败",
                  message: result.message,
                  type: "error"
                });
              }
            });
        })
        .catch(() => {});
    },
    changeStartEnd() {
      console.log(this.startEnd);
      this.MaintenanceSearchForm.start = this.startEnd[0];
      this.MaintenanceSearchForm.end = this.startEnd[1];

      // console.log(this.chooseSearchForm);
      this.MaintenanceSearchForm.id = this.chooseSearchForm.id;
      this.MaintenanceSearchForm.type = "2";
      addMaintenance.maintainList(this.MaintenanceSearchForm).then(res => {
        if (res.code === 200 && res.result) {
          console.log(111, res);
          this.MaintenanceData = res.result.records;
          console.log(this.MaintenanceData);
          this.total = res.result.total;
        }
      });
    },
    /** 维修记录下载 */
    handleDownloads() {
      var url =
        "/api/excel/exportDeviceMaintain?id=" +
          this.MaintenanceSearchForm.id +
          "&type=" +
          this.MaintenanceSearchForm.type +
          "&start=" +
          this.MaintenanceSearchForm.start ||
        "" + "&end=" + this.MaintenanceSearchForm.end ||
        "";
      window.open(url);
      this.MaintenanceRecords = false;
    },
    //---------------------保养登记--------------------------
    //开弹窗
    editInfo(row) {
      console.log(row);
      this.Maintenanceadd.deviceId = row.id;
      this.Maintenanceadd.type = "1";
      console.log(this.Maintenanceadd.deviceId);
      this.maintenance1Visible = true;
    },
    // 传数据
    MaintenanceConfirm1() {
      addMaintenance.add(this.Maintenanceadd).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: "成功",
            message: res.message,
            type: "success"
          });
          this.handleSearch();
          this.maintenance1Visible = false;
        } else {
          this.$notify({
            title: "失败",
            message: res.message,
            type: "error"
          });
        }
      });
    },
    //---------------------保养记录--------------------------
    submitExamine(row) {
      this.startEnd = "";
      this.MaintenanceSearchForm.start = "";
      this.MaintenanceSearchForm.end = "";
      this.Maintenancerecord = true;
      this.chooseSearchForm = row;
      console.log(this.chooseSearchForm);
      this.MaintenanceSearchForm.id = row.id;
      this.MaintenanceSearchForm.type = "1";

      addMaintenance.maintainList(this.MaintenanceSearchForm).then(res => {
        if (res.code === 200 && res.result) {
          console.log(111, res);
          this.MaintenanceData = res.result.records;
          console.log(this.MaintenanceData);
          this.total = res.result.total;
        }
      });
    },
    // 修改
    handleUpdate2(row) {
      // console.log(1111);
      this.maintenance3Visible = true;
      console.log(row);
      this.MaintenanceData2 = row;
    },
    // 修改确认
    confirmDialog1() {
      console.log(123);
      this.$refs.MaintenanceData2.validate(valid => {
        if (valid) {
          addMaintenance
            .update(this.MaintenanceData2)
            .then(request => {
              this.$notify({
                title: "成功",
                message: request.message,
                type: "success"
              });
              this.maintenance3Visible = false;
              this.$refs.customForm.resetFields();
            })
            .catch(() => {});
        } else {
          return false;
        }
      });
    },
    // 删除
    handleDelete1(row) {
      console.log(row);
      this.id = row.id;
      console.log(this.id);
      this.$confirm(
        '是否确认删除名称为"' + row.createUser + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          addMaintenance
            .deletedelete({
              id: this.id
            })
            .then(result => {
              if (result.code === 200) {
                this.$notify({
                  title: "成功",
                  message: result.message,
                  type: "success"
                });
                this.Maintenancerecord = false;
              } else {
                this.$notify({
                  title: "失败",
                  message: result.message,
                  type: "error"
                });
              }
            });
        })
        .catch(() => {});
    },
    changeStart() {
      this.MaintenanceSearchForm.start = this.startEnd[0];
      this.MaintenanceSearchForm.end = this.startEnd[1];

      // console.log(this.chooseSearchForm);
      this.MaintenanceSearchForm.id = this.chooseSearchForm.id;
      this.MaintenanceSearchForm.type = "1";
      addMaintenance.maintainList(this.MaintenanceSearchForm).then(res => {
        if (res.code === 200 && res.result) {
          console.log(111, res);
          this.MaintenanceData = res.result.records;
          console.log(this.MaintenanceData);
          this.total = res.result.total;
        }
      });
    },

    /** 保养记录下载 */
    handleDownload() {
      var url =
        "/api/excel/exportDeviceMaintain?id=" +
          this.MaintenanceSearchForm.id +
          "&type=" +
          this.MaintenanceSearchForm.type +
          "&start=" +
          this.MaintenanceSearchForm.start ||
        "" + "&end=" + this.MaintenanceSearchForm.end ||
        "";
      window.open(url);
      this.Maintenancerecord = false;
    }
  }
};
</script>

<style scoped lang="scss" type="text/scss">
.clearfix {
  line-height: 40px;
  display: flex;
}
.install-title {
  display: flex;
  align-items: center;
  line-height: 50px;
  padding-left: 20px;
  color: #fff;
  background-color: #d7dae2;
  justify-content: flex-start;
  margin-bottom: 10px;
}
.time-dot {
  text-align: center;
  justify-content: center;
  padding-top: 4px;
  position: relative;
  border-radius: 50%;
  background: #dfe4ed;
  height: 25px;
  width: 25px;
  left: -7px;
}
.search_div {
  > div {
    &:nth-child(1) {
      margin-right: 10px;
    }
    display: inline-block;
  }
}

.search_input {
  width: 200px;
  margin-bottom: 5px;
}
.search-right {
  text-align: right;
  padding-right: 25px;
}
.item {
  font-size: 16px;
}
::v-deep .el-card .el-card__header {
  padding: 5px 20px;
  background: #f3f2f2;
}
</style>
